
#include "stack_base_list.h"
#include <stdio.h>
#include <stdlib.h>

/*创建节点*/
STACK_NODE *node_create(int data,STACK_NODE *next)
{
	STACK_NODE *node = malloc(sizeof(STACK_NODE));
	node->data = data;
	node->next = next;
    return node;
}
/*销毁节点*/
STACK_NODE * node_destroy(STACK_NODE *node)
{	
	STACK_NODE *next = node->next;
	free(node);
	return next;
}
/*创建栈*/
STACK *stack_create(void)
{
	STACK *stack = malloc(sizeof(STACK));
	stack->top = NULL;
	return stack;
}
void stack_clear(STACK *stack)
{
	while(stack->top)
	{
		stack->top = node_destroy(stack->top);
	}
}

/*销毁栈*/
void stack_destroy(STACK *stack)
{
	/*清空栈*/
	stack_clear(stack);
	free(stack);// ?????
}
/*压栈*/
void stack_push(STACK *stack, int data)
{
	/*
	* 1 申请节点并初始化，让该节点的next指向老的栈顶
	* 2 top指针指向新的栈顶
     */
	stack->top = node_create(data, stack->top);
}
/*弹栈*/
int stack_pop(STACK *stack)
{
	int data = stack->top->data;
    stack->top = node_destroy(stack->top);
	return data;
}
/*判空 如果为空返回1 ，否则返回0*/
int stack_empty(STACK *stack)
{
	return !stack->top;
}
/*判满*/
int stack_full(STACK *stack)
{
	return 0;
}


